#ifndef __TASK_H_
#define __TASK_H_

#include <iostream>
#include <pthread.h>
#include "util.h"

class Task {
    public:
        unsigned int id;  /*ID given for each task */
        unsigned int priority; /* a user assigned priority to the task in question */
        pthread_mutex_t dmutex;
        pthread_cond_t tdone;
        bool _Done;
        TState_t * myState; /* pointer to a state enum, can be used to manage children or to declare my state */
        TState_t doneState; /* state to depict end for deleting */
    public:

        void lock_d() {
            pthread_mutex_lock(&dmutex);
        } 

        void release_d() {
            pthread_mutex_unlock(&dmutex);
        }

        Task() { /* default constructor */
            id = 0; 
            _Done = false;
            doneState = Create;
            pthread_mutex_init(&dmutex, NULL);
            pthread_cond_init(&tdone, NULL);
        }

        Task(unsigned int i) {/* constructor */
            id = i;
            _Done = false;
            doneState = Create;
            pthread_mutex_init(&dmutex, NULL);
            pthread_cond_init(&tdone, NULL);
        }

        virtual ~Task(){
        }

        virtual void run () = 0; // virtual function that the user must override //

        virtual void doneWithTask() {
            delete this;
        }

        //virtual char* whoami(int& i) = 0;

        virtual void done() {
            doneState = Done;
            delete this;
        }

        virtual void print() {// printing function for testing purposes //
        }

};

#endif 
